<template>
  <div>
    <a-descriptions bordered size='small' :column='3'>
      <a-descriptions-item label='单号'>
        {{ orderInfo.orderNo }}
      </a-descriptions-item>
      <a-descriptions-item label='制单人'>
        {{ orderInfo.nickName }}
      </a-descriptions-item>
      <a-descriptions-item label='发货日期'>
        {{ orderInfo.sendDate }}
      </a-descriptions-item>
      <a-descriptions-item label='订单日期'>
        {{ orderInfo.createTime }}
      </a-descriptions-item>
      <a-descriptions-item label='部门'>
        {{ orderInfo.deptName }}
      </a-descriptions-item>
      <a-descriptions-item label='业务员'>
        {{ orderInfo.saleManName }}-{{ orderInfo.linkTel }}
      </a-descriptions-item>
      <a-descriptions-item label='供货方'>
        {{ orderInfo.supplierName }}
      </a-descriptions-item>
      <a-descriptions-item label='购货方'>
        {{ orderInfo.customName }}
      </a-descriptions-item>

      <a-descriptions-item label='供方资信'>
        <a-tag color='#2db7f5' v-if='orderInfo.supplierBondType==0'>不垫付</a-tag>
        <a-tag color='purple' v-if='orderInfo.supplierBondType==1'>底价</a-tag>
        <a-tag color='purple' v-if='orderInfo.supplierBondType==2'>底价+税金</a-tag>
        <a-tag color='purple' v-if='orderInfo.supplierBondType==3'>税金</a-tag>
        <a-tag color='purple' v-if='orderInfo.supplierBondType==6'>底价/2+税金</a-tag>
        <a-tag color='purple' v-if='orderInfo.supplierBondType==5'>全额垫付</a-tag>
        <a-tag color='purple' v-if='orderInfo.supplierBondType==8'>销售金额*费率</a-tag>

      </a-descriptions-item>
      <a-descriptions-item label='购方资信'>
        <a-tag color='#2db7f5' v-if='orderInfo.customBondType==0'>全款</a-tag>
        <a-tag color='purple' v-if='orderInfo.customBondType==1'>底价</a-tag>
        <a-tag color='purple' v-if='orderInfo.customBondType==2'>底价+税金</a-tag>
        <a-tag color='purple' v-if='orderInfo.customBondType==6'>底价/2+税金</a-tag>
        <a-tag color='purple' v-if='orderInfo.customBondType==3'>税金</a-tag>
        <a-tag color='purple' v-if='orderInfo.customBondType==5'>全额资信</a-tag>
        <a-tag color='purple' v-if='orderInfo.customBondType==7'>预付款</a-tag>
      </a-descriptions-item>

      <a-descriptions-item label='订单状态'>
        <a-tag color='#87d068' v-if='orderInfo.orderState==0'>未提交</a-tag>
        <a-tag color='#87d068' v-if='orderInfo.orderState==1'>{{ orderInfo.taskName }}</a-tag>
        <a-tag color='#f50' v-if='orderInfo.orderState==2'>已审批</a-tag>
      </a-descriptions-item>

      <a-descriptions-item label='收款金额'>
        {{ orderInfo.takeAmount }} <span v-if='orderInfo.overAmount>0'>(多收金额:{{orderInfo.overAmount}})</span>
      </a-descriptions-item>
      <a-descriptions-item label='收款账户'>
        {{ orderInfo.bankName }}
      </a-descriptions-item>
      <a-descriptions-item label='收款日期' :span="2">
        {{ orderInfo.takeDate }}
      </a-descriptions-item>
      <a-descriptions-item label='备注' :span="3">
        {{ orderInfo.remark }}
      </a-descriptions-item>
      <a-descriptions-item label='附件' :span="3">
        <f-images :value="orderInfo.orderImage"></f-images>
      </a-descriptions-item>
    </a-descriptions>
      <a-divider orientation="left">结算单信息</a-divider>
      <a-descriptions bordered size="small" :column="2">
        <a-descriptions-item label="部门" :span="2">
          {{formItem.deptName}}
        </a-descriptions-item>
        <a-descriptions-item label="部门负责人">
          {{formItem.deptSaleManName}}
        </a-descriptions-item>
        <a-descriptions-item label="收款人">
          {{formItem.saleManName}}
        </a-descriptions-item>
        <a-descriptions-item label="收款银行">
          {{formItem.bankName}}
        </a-descriptions-item>
        <a-descriptions-item label="收款账户">
          {{formItem.bankNo}}
        </a-descriptions-item>
        <a-descriptions-item label="结算金额">
          <span v-if='formItem.hasError==0'>{{formItem.amount}}</span>
          <a-tag color='#f50' v-if='formItem.hasError==1' title='金额异常,请重新申请'> {{formItem.amount}}</a-tag>
        </a-descriptions-item>
        <a-descriptions-item label="结算日期">
          {{formItem.amountDate}}
        </a-descriptions-item>
        <a-descriptions-item label="附件" :span="2">
          <f-images :value="formItem.paymentImage"></f-images>
        </a-descriptions-item>
        <a-descriptions-item label="备注" :span="2">
          {{formItem.remark}}
        </a-descriptions-item>
      </a-descriptions>

      <a-divider orientation="left">结算明细</a-divider>
      <f-table ref="table" rowKey="settleId" :columns="columns"  :exportBtn="true" :scroll="{x:true}" :multiple="false" handler="yesSettlePageListHandler" :operator="operator" :autoLoad="false" :params="queryParam" :api="api.bod" exportUrl='exportSettleDetails'>
          <span slot="action" slot-scope="text, record">
          <template>
            <a @click="$refs.orderInfoDrawer.showDrawer(record)" >查看</a>
          </template>
        </span>
      </f-table>
    <order-info-drawer ref='orderInfoDrawer'></order-info-drawer>
  </div>
</template>
<script>

  import api from './../js/api'
  import OrderInfoDrawer from '@/views/module/business/order/order_info_drawer'

  export default {
    name: 'SettleDetails',
    components: { OrderInfoDrawer },
    data() {
      let me = this
      //操作按钮
      let operator = []
      return {
        api: Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: {},
        invoiceDetailsModal: false,
        supplierRetable: 0,
        supplierId: '',
        selectIds: '',
        modalTitle: '开票申请确认',
        params1: {
          formulaType: 5
        },
        params2: {
          bankType: 1
        },
        orderInfo:{},
        formItem: this.getFormItem(),
        // 表头
        columns: [
          {
            title: '操作',
            align: 'center',
            width: '80px',
            scopedSlots: { customRender: 'action' }
          },
          {
            title: '单号',
            align: 'center',
            dataIndex: 'orderNo'
          },
          {
            title: '发货日期',
            align: 'center',
            dataIndex: 'sendDate'
          },
          {
            title: '购货方',
            align: 'center',
            dataIndex: 'customName'
          },
          {
            title: '商品名称',
            align: 'center',
            dataIndex: 'drugsName'
          },
          {
            title: '规格',
            align: 'center',
            dataIndex: 'drugsSpec'
          },
          {
            title: '数量',
            align: 'center',
            dataIndex: 'saleNum'
          },
          {
            title: '单价',
            align: 'center',
            dataIndex: 'salePrice'
          },
          {
            title: '发货金额',
            align: 'center',
            isStatistics: true,
            dataIndex: 'saleAmount'
          },
          {
            title: '应返金额',
            align: 'center',
            isStatistics: true,
            dataIndex: 'supplierRetable'
          },
          {
            title: '实返金额',
            align: 'center',
            isStatistics: true,
            dataIndex: 'supplierRealAmount'
          },
          {
            title: '返款日期',
            align: 'center',
            isStatistics: true,
            dataIndex: 'supplierRetDate'
          },
          {
            title: '回款金额',
            align: 'center',
            isStatistics:true,
            dataIndex: 'returnAmount'
          },
          {
            title: '回款日期',
            align: 'center',
            dataIndex: 'returnDate'
          },

          {
            title: '应结算额',
            align: 'center',
            isStatistics: true,
            dataIndex: 'settleAmount'
          },
          {
            title: '应结算额2',
            align: 'center',
            isStatistics: true,
            dataIndex: 'settleAmount2'
          },
          {
            title: '应结算额3',
            align: 'center',
            isStatistics: true,
            dataIndex: 'settleAmount3'
          },
          {
            title: '应退保证金',
            align: 'center',
            isStatistics: true,
            dataIndex: 'customBond'
          }
        ],
        operator: operator
      }
    },
    created() {
    },
    methods: {
      getFormItem() {
        return {
          invoiceId: '',
          companyId: '',
          supplierId: '',
          deptName: '',
          deptSaleManName: '',
          saleManName: '',
          amountFormulaId: null,
          invoiceUnitId: null,
          taxAmount: '',
          invoiceAmount: '',
          invoiceDate: '',
          bankId: null,
          invoiceType: null,
          userId: '',
          invoiceState: '',
          remark: ''
        }
      },
      setData(data) {
        this.formItem = this.getFormItem()
        if (data && data.paymentId) {
          let params = {
            paymentId: data.paymentId,
            handlerName: 'settlePaymentGetHandler'
          }
          this.queryParam.paymentId = data.paymentId
          this.http.get(this, {
            url: this.api.payment.get,
            params: params,
            success: function(me, data) {
              me.formItem = data
              me.loaded = true
            }
          })

          this.http.get(this, {
            url: this.api.busOrder.get,
            params: {
              orderId: data.orderId,
              handlerName: "orderGetHandler"
            },
            success: function(me, data) {
              me.orderInfo = data
            }
          })
          this.$refs['table'].refresh(false)
        }
      }
    }
  }
</script>
